package com.ruoyi.iot.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.customer.api.factory.RemoteCustomerFallbackFactory;
import com.ruoyi.iot.api.RemoteIotService;
import com.ruoyi.iot.api.domain.HealthDatas;
import com.ruoyi.iot.api.domain.HeathParam;
import com.ruoyi.iot.api.domain.PushInfo;
import com.ruoyi.iot.api.domain.WatchInfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;

public class RemoteIotFallbackFactory implements FallbackFactory<RemoteIotService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteCustomerFallbackFactory.class);
    @Override
    public RemoteIotService create(Throwable cause) {
        log.error("iot服务调用失败:{}", cause.getMessage());
        return new RemoteIotService() {

            @Override
            public R<WatchInfoVO> getLastMessageByCustomerIdDate(Long customerId, String date, String source) {
                return R.fail("查询设备消息失败:" + cause.getMessage());
            }

            @Override
            public R<Boolean> addmockData(Long customerId, String source) {
                return R.fail("新增设备mock消息失败:" + cause.getMessage());
            }

            @Override
            public R<HealthDatas> getHealthDataInner(@RequestBody HeathParam healthParam, String source) {
                return R.fail("获取设备日数据失败" + cause.getMessage());
            }

            @Override
            public R pushHandler(PushInfo pushInfo, String source) {
                return R.fail("推送消息失败" + cause.getMessage());
            }

            @Override
            public R<HealthDatas> getLastWeekHealthDataInner(HeathParam healthParam, String source) {
                return R.fail("获取设备周数据失败" + cause.getMessage());
            }

            @Override
            public R<HealthDatas> getLastMonthHealthDataInner(HeathParam healthParam, String source) {
                return R.fail("获取设备月数据失败" + cause.getMessage());
            }


        };
    }
}
